package cn.hxzy.icon.icon.entity.vo;

import lombok.Data;

@Data
public class ReturnBean {
    private Integer code;
    private String msg;
    private Object data;

    //    无参构造私有化（避免新建对象）
    private ReturnBean(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    private ReturnBean() {
    }

    public static ReturnBean of(AnswerCode answerCode, Object obj) {
        return new ReturnBean(answerCode.code, answerCode.msg, obj);
    }

    public static ReturnBean of(AnswerCode answerCode) {
        return new ReturnBean(answerCode.code, answerCode.msg, null);
    }

    //    编码枚举
    public enum AnswerCode {

        SUCCESS("操作成功", 200),
        UNKNOWN_ERROR("登录名已存在", 500),
        PARAMETER_ERROR("参数错误", 400),
        NOT_LOGIN("未经授权", 401),
        ADD_ERROR("添加出错", 402),
        NOT_PERMISSION("服务器已拒绝", 403),
        OBJECT_NOT_EXIST("对象不存在", 404),
        METHOD_NOT_SUPPORTED("方法不被支持", 405),
        UPDATE_ERROR("修改出错", 406),
        DELETE_ERROR("删除出错", 407),
        VERIFY_ERROR("验证码有误！",408),
        VERIFY_NOT_EXIST("请填写验证码！",409),
        AUTH_ERROR("账户或密码有误！", 410);


        private Integer code;
        private String msg;

        AnswerCode(String msg, Integer code) {
            this.msg = msg;
            this.code = code;
        }
    }
}
